<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1.0, maximum-scale=1.0"/>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
    <title>我的红包</title>
    <meta name="format-detection" content="telephone=no"/>
    <link href="{$resroot}list.css?v=1" rel="stylesheet" type="text/css">
</head>
<body>
<div class="dj-base-wrap">

    <input type="hidden" id="hideMenu">

    <div class="header">
    </div>
    <ul class="mian" id="mainlist">
    </ul>
</div>
<a class="footer" href="{php echo $this->createMobileUrl('index',array('id'=>$id))}">邀请好友获得更多的红包!</a>
    
</body>
<script type="text/javascript" src="{$resroot}jquery.js"></script>
<script type="application/javascript" src="{$resroot}fastclick.js"></script>
<script type="text/javascript">
$(function(){
    FastClick.attach(document.body);
});
</script>
<script type="text/javascript" src="{$resroot}ajax-loading.js?v=1"></script><script type="text/javascript">
    var pageIndex = 1;
    var pageSize = 10;
    var isload = true; //判断是否存在下一页
    var reload = true; //判断是否重复加载

    function formatDate(now) {
        var year = now.getFullYear();
        var month = now.getMonth() + 1;
        var date = now.getDate();
        var hour = now.getHours();
        var minute = now.getMinutes();
        var second = now.getSeconds();
        return   year + "-" + month + "-" + date + "   " + hour + ":" + minute + ":" + second;
    }

    list();
    function list() {
        if (!isload) {
            return;
        }
        if (!reload) {
            reload = false;
        }
        $.ajax({
            url: "{php echo $this->createMobileUrl('mylist',array('op'=>'list'))}",
            data: {"openid":"{$openid}","id":"{$id}","pageIndex": pageIndex, "pageSize": pageSize},
            type: "post",
            dataType:"json",
            success: function (jsonData) {
                try {
                    reload = true;
                    if (jsonData.list.length == 0 || jsonData.total <= (pageIndex + 1) * pageSize) {
                        isload = false;
                    }
                    pageIndex += 1;
                    var html = "";
                    $.each(jsonData.list, function (i, e) {
                        //html += getHtml(111, "asdfasdf", e.createtime, e.points, e.consumetime, e.statuss);
                        html += getHtml(e);
                    });
                    $("#mainlist").append(html);
                } catch (e) {
                    console.error(e.message);
                    xh_ajaxError();
                }
            }
        });
    }
function getHtml(e) {
        var html = '';
        var exp= e.createtimestr + '--' + e.endtimestr;
        if( e.createtime>e.endtime )
        {
            html = '<li class="clearfix old"><div class="left"><p>' +  e.name + '</p><p>' + exp + '</p></div><div class="right"><a class="btn disabled" href="#">过期</a></div><div class="right"><p class="right_t">￥' + e.points  + '</p><p class="right_b"></p></div></li>';
        }
        else{
            if (e.status == 0) {
               html = '<li class="clearfix new"><div class="left"><p>' + e.name + '</p><p>' + exp + '</p></div><div class="right"><a class="btn " href="#">处理中</a></div><div class="right"><p class="right_t">￥' + e.points + '</p><p class="right_b"></p></div></li>';
           } else if (e.status == 1) {
               html = '<li class="clearfix old"><div class="left"><p>' +  e.name + '</p><p>' + exp + '</p></div><div class="right"><a class="btn disabled" href="#">已提现</a></div><div class="right"><p class="right_t">￥' + e.points  + '</p><p class="right_b"></p></div></li>';
           }   
        }
        return html;
    }
   
    $(function () {
        $(window).scroll(function () {
            var totalheight = parseFloat($(window).height()) + parseFloat($(window).scrollTop());
            if ($(document).height() <= totalheight) {
                list();
            }
        });
    });
</script>
</html>

